from tools import *

class Solution:
    def oddEvenList(self, head: ListNode) -> ListNode:
        if head == None or head.next == None: return head
        odd_head, even_head = head, head.next
        even_tmp, odd_tmp = even_head, odd_head
        tmp = head.next
        while tmp.next:
            tmp = tmp.next
            odd_tmp.next = tmp
            odd_tmp = odd_tmp.next
            if tmp.next:
                even_tmp.next = tmp.next
                even_tmp = even_tmp.next
                tmp = tmp.next
        odd_tmp.next = even_head
        even_tmp.next = None
        return odd_head

